#coding=utf-8
import unittest
import os
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import cx_Oracle
from Tool import DatabaseOperate
from Tool import usefulTools

db_operate_instances = DatabaseOperate.database_operate()
data_handle_instances = DatabaseOperate.data_handle_operate()
usefulTools_instances = usefulTools.userfulToolsFactory()

class function_test():
    def test(self):
        print 'test'

    def db_oracle_select(self):
        print 'oracle select test'
        dbconn = cx_Oracle.connect('dlsys','dlsys','192.168.101.14/cgdb0501')
        db_cursor = dbconn.cursor()
        # sql = "select * from dlmis.to_rec t where t.task_num = 201708310001"
        # sql = "select * from dlsys.tc_human t where t.human_name = '市值班长'"
        test = '%测试'
        # sql = 'select human_name from tc_human where human_name like ' + "'%测试'"
        sql =  'select human_id,human_name from tc_human where human_name like \'' + test +'\''
        # sql = 'update dlsys.tc_human_nav_item t set desktop_flag=1, desktop_left =60, desktop_top = 210 where t.human_id = 10 and t.nav_item_id = 2'
        print sql
        db_cursor.execute(sql.decode('utf-8').encode('GBK'))
        result_list = db_cursor.fetchall()
        db_cursor.close()
        dbconn.close()
        for i in range(len(result_list)):
            human_name = result_list[i][1]
            print str(human_name).decode('GBK').encode('utf-8')

    def db_oracle_update(self):
        print 'oracle select test'
        dbconn = cx_Oracle.connect('dlsys','dlsys','192.168.101.14/cgdb0501')
        db_cursor = dbconn.cursor()
        sql = 'update dlsys.tc_human_nav_item t set desktop_flag=1, desktop_left =60, desktop_top = 210 where t.human_id = 10 and t.nav_item_id = 2'
        print sql
        db_cursor.execute(sql.decode('utf-8').encode('GBK'))
        dbconn.commit()
        db_cursor.close()
        dbconn.close()

    #测试箱子是否在人员的箱子列表中
    def task_in_humanTaskList_judge(self):
        task_list = db_operate_instances.get_tasklist_infor(11,3)
        for i in range(len(task_list)):
            print task_list[i]
            if 'rec_recyclelist' not in task_list[i]:
                print u'无作废栏，继续'
                if i == len(task_list) -1:
                    print '===========直接抛异常出去========='
                continue
            else:
                print u'作废栏存在'
                break
            print u'测试不打印'
        print u'继续测试'

    def test_in_function(self):
        if 1 in (1,2,3):
            print u'test'

    #测试处理字符串的功能
    def stringDeal(self):
        str = '要求市接线员0316等9人在今天21时之前回复'
        str_deal_later = usefulTools_instances.SubString_handle(str,'要求','等')
        print str_deal_later

    def testWhile(self):
        i=0
        while(True):
            if i==2:
                print i
                break
            else:
                i = i+1
        print u'测试继续。。。'


if __name__ == '__main__':
    test = function_test()
    # userfulToolsFactory.creat_dir(test,'D://Cruise//pythonSrc//reprot//')
    # case = 'u"StartTest(/''login_egova/'')"'
    # test.CaseNameOp(case)
    # test.update_file_path_deal('D:/SVN/V15/zx2016/Client/Python/eUrbanMIS/updatefile/9.jpg')
    # test.Oracel_data_deal('(1234,)')
    # test.get_current_position()
    # test.db_oracle_update()
    # db_operate_instances.update_nav_item(60,210,10,2)
    # db_operate_instances.get_tasklist_infor(10,1)
    # db_operate_instances.get_human_infor_by_username('test')
    # db_operate_instances.get_wf_act_def(108)
    # db_operate_instances.get_wf_trans_def(37)
    # db_operate_instances.get_wf_process_group_num()
    # data_handle_instances.get_wf_process_group_num()
    # data_handle_instances.arrange_wf_process()
    # test.test_in_function()
    # tasknum = db_operate_instances.get_rec_infor_by_menuType('transit','(3,4,6)')
    # print tasknum[1]
    # test.task_in_humanTaskList_judge()
    # test.stringDeal()
    test.testWhile()
    unittest.main()


